import * as React from 'react'
import { ShopcarService } from '../../services/shopcarService'
import { Product } from '../../services/productModel'

interface Props {}
interface State {
  products: Product[]|null
  test: string
}
export default class Page extends React.Component<Props, State> {
  readonly state: State = {
    products: null,
    test: ''
  }
  public componentDidMount () {
    ShopcarService.product$.subscribe(products => {
      products && this.setState((prevState) => {
        // return Object.assign(prevState, {
        //   products: products,
        // })
        return {
          test: '1'
        }
      })
    })
  }
  public render () {
    return (
      <>
        <div>i am shopping car</div>
        <div>--------------</div>
        <div>{ JSON.stringify(this.state.products) }</div>
        <div>--------------</div>
        <div>{ this.state.test }</div>
      </>
    )
  }
}
